
/**
 * @typedef CreateSite
 * @property {string} name.required -站点名称描述
 * @property {string} url.required -站点url
 * @property {string} folderId.required -文件夹id
 */

/**
 * @typedef UpdateSite
 * @property {string} id.required -站点id
 * @property {string} name.required -站点名称描述
 * @property {string} url.required -站点url
 */

const express = require('express')
const router = express.Router()
const auth = require('@/middleware/auth.middleware')
const sitesController = require('@/controllers/sites.controller')

/**
 * 查询文件夹下的站点列表
 * @route GET /sites
 * @group 站点管理
 * @param {string} folderId.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 */
router.get('/', sitesController.findUserSites)

/**
 * 查询工具树列表
 * @route GET /sites/list-tree
 * @group 站点管理
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 */
router.get('/list-tree', sitesController.findToolTreeList)

/**
 * 查询工具树列表
 * @route GET /sites/list-by-name
 * @group 站点管理
 * @param {string} name.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 */
router.get('/list-by-name', sitesController.findToolByName)

/**
 * 新增站点
 * @route POST /sites/create
 * @group 站点管理
 * @param {CreateSite.model} createSite.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/create', auth(), sitesController.additionSite)

/**
 * 删除站点
 * @route GET /sites/delete
 * @group 站点管理
 * @param {string} id.query.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.get('/delete', auth(), sitesController.deleteSite)

/**
 * 更新站点
 * @route POST /sites/update
 * @group 站点管理
 * @param {UpdateSite.model} updateSite.body.required
 * @returns {object} 200
 * @returns {Error}  default - Unexpected error
 * @security JWT
 */
router.post('/update', auth(), sitesController.updateSite)

module.exports = router
